package com.atsansan.mywork.login.controller;

import com.atsansan.mywork.login.entity.BookEntity;
import com.atsansan.mywork.login.entity.UserEntity;
import com.atsansan.mywork.login.service.UserService;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author sansan
 * @create 2021-03-26 10:27
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;


    @RequestMapping("/listU")
    public String list(Map<String,Object> map){
        List<UserEntity> userList = userService.list();
        map.put("userList",userList);
//        System.out.println(userList.toString());
        return "listU";
    }

    @RequestMapping("/update/{id}")
    public String updateById(@PathVariable("id") Long id,Map<String,Object> map){
        UserEntity userEntity = userService.getById(id);
        map.put("userEntity",userEntity);
        return "updateU";
    }
    @RequestMapping("updateU")
    private String update(UserEntity userEntity){
        userService.updateById(userEntity);
        return "redirect:/user/listU";
    }
    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable("id") Long id){
        userService.removeById(id);

        return "redirect:/user/listU";
    }
}
